class RecentCounter {
    static final int num=3000;
    Queue <Integer> queue;

    public RecentCounter() {
        queue=new ArrayDeque<Integer>();

    }

    public int ping(int t) {
        while(!queue.isEmpty()&&queue.peek()<t-num){
            queue.poll();
        }
        queue.offer(t);
        return queue.size();

    }
}

/**
 * Your RecentCounter object will be instantiated and called as such:
 * RecentCounter obj = new RecentCounter();
 * int param_1 = obj.ping(t);
 */